package com.projeto.sistema.vendas;

import org.apache.log4j.Logger;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

public class HibernateUtil {

	private static final SessionFactory	session	= buildSessionFactory();
	private static final Logger			logger	= Logger.getLogger(HibernateUtil.class);

	private static SessionFactory buildSessionFactory() {

		try {
			Configuration configuracaoHibernate = new Configuration();
			configuracaoHibernate.configure("hibernate.cfg.xml");
			return configuracaoHibernate.buildSessionFactory();
		} catch (Throwable e) {
			System.out.println("Deu Erro!!" + e);
			logger.error(e.getMessage(), e);
			throw new ExceptionInInitializerError();
		}
	}

	public static SessionFactory getSession() {
		return session;
	}
}
